<?php include('header.php');?>
$i=0;
$a=5;
echo $i+$a;
<?php
echo "<pre>";
print_r($_POST);
echo "</pre>";
?>
<script type="text/javascript">
var counter = 2;
function addTr(){
	//var count = parseInt(document.getElementById('LTr').value);
	//var counter = count + 1;
	var tr =   $('<tr id="firstTr'+ counter +'"><td class="pLeft"><input type="text" name="list[]" id="list'+ counter +'" size="30" /></td><td class="center"><input type="text" name="amount[]" id="amount'+ counter +'" size="2" style="text-align: right;" /></td><td class="center"><input type="text" name="price['+ counter +']" onkeyup="SumGroup();"  size="5" style="text-align: right;" /></td><td class="pRight">0</td><td class="center"><button onclick="TrRemove(\'firstTr'+ counter +'\');" type="button">-</button></td></tr>');
  	$('#myTbl').append(tr);
  	counter++;

  	var counterG = parseInt(document.getElementById('CountG').value);
  	var countG = counterG + 1;
  	document.getElementById('CountG').value = countG;
  	//document.getElementById('LTr').value = counter;

	//	$("#myTbl").append($("#firstTr").clone());
}

function TrRemove(id){
	$('#' + id).remove();
	var counter = parseInt(document.getElementById('CountG').value);
	var countG = counter - 1;
	document.getElementById('CountG').value = countG;
}
//รวมเงินเมื่อเลือก group
function SumGroup(num){
	var amount = document.getElementById('amount'+num).value;
	var price = document.getElementById('price'+num).value;
	var total = amount * price;
	document.getElementById('total2'+ num).value = total
	document.getElementById('total'+num).innerHTML = total;
	TotalGroup();
}

function TotalGroup(){
		var total = parseInt(0);
	for(var i=1; i<=20; i++){
			total = total + parseInt(document.getElementById('total2'+ i).value);
	}
	document.getElementById('totala2').innerHTML = total;
}
</script>
<span id="totala2"></span>
<form id="form1" name="form1" action="" method="post">
<table  id="myTbl" class="list">
<thead>
  <tr>
  	<td class="center">ลำดับ</td>
    <td class="center">รายการ</td>
    <td class="center">จำนวน</td>
    <td class="center">ราคา/หน่วย</td>
    <td class="center">รวม</td>
  </tr>
</thead>
<?php for($i=1;$i<=20;$i++){?>
  <tr>
    <td class="center"><?php echo $i;?></td>
    <td class="pLeft"><input type="text" name="list[]" id="list<?php echo $i;?>" size="30" /></td>
    <td class="center"><input type="text" name="amount[]" id="amount<?php echo $i;?>" onkeyup="SumGroup('<?php echo $i;?>');" id="amount1" size="2" style="text-align: right;" /></td>
    <td class="center"><input type="text" name="price[]" id="price<?php echo $i;?>" onkeyup="SumGroup('<?php echo $i;?>');" size="5" style="text-align: right;" /></td>
    <td class="pRight"><input type="hidden" name="total2[]" id="total2<?php echo $i;?>" value="0" /><span id="total<?php echo $i;?>"></span></td>
  </tr>
<?php } ?>
</table>
<input type="submit" name="submit" value="submit"/>
</form>
<input type="hidden" name="CountG" id="CountG" value="1" />
<div><button id="addRow" onclick="addTr();" type="button">+</button></div>
<?php include('footer.php');?>